public class ArrayQueue<E> implements Queue<E> {
    private Array<E> array;

    public ArrayQueue(int capacity) {
        array = new Array<>(capacity);
    }

    public ArrayQueue() {
        array = new Array<>();
    }

    public int getCapacity() {
        return array.getCapacity();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    /**
     * 向队列末尾中添加元素
     * @param element 要添加的元素
     */
    @Override
    public void enqueue(E element) {
        array.push(element);
    }

    /**
     * 删掉队列头部的元素
     * @return 返回被删掉的元素
     */
    @Override
    public E dequeue() {
        return array.shift();
    }

    @Override
    public E getHead() {
        return array.get(0);
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append("Queue: ");
        result.append("front [");
        for (int i = 0; i < array.getSize(); i++) {
            result.append(array.get(i));
            if (i != array.getSize() - 1) {
                result.append(", ");
            }
        }
        result.append("] tail");
        return result.toString();
    }
}
